package com.study.utils.mybatisplus;

import com.study.model.dto.StudentQueryDTO;
import com.study.model.entity.StudentDO;
import com.study.result.AjaxResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;


/**
 * 使用mybatis plus
 * 学生 Controller
 */
@RestController
@RequestMapping("/plus")
public class PStudentController {

    @Resource
    private PStudentService pStudentService;

    /**
     * 获取学生信息
     */
    @GetMapping("/{id}")
    public AjaxResult get(@PathVariable Long id) {
        return AjaxResult.success(pStudentService.selectStudentById(id));
    }

    /**
     * 获取学生列表
     */
    @GetMapping("/list")
    public AjaxResult list(StudentQueryDTO studentQueryDTO) {
        return AjaxResult.success(pStudentService.selectStudentList(studentQueryDTO));
    }

    /**
     * 新增
     */
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody StudentDO studentDO) {
        return AjaxResult.success(pStudentService.insertStudent(studentDO));
    }

    /**
     * 修改（为了迁就参数校验，修改的参数也跟保存一致，有三个必传）
     */
    @PostMapping("/update")
    public AjaxResult edit(@Validated @RequestBody StudentDO studentDO) {
        return AjaxResult.success(pStudentService.updateStudent(studentDO));
    }

    /**
     * 删除
     */
    @PostMapping("/remove")
    public AjaxResult remove(Long id) {
        return AjaxResult.success(pStudentService.deleteStudentById(id));
    }

    /**
     * 批量删除
     */
    @PostMapping("/delete")
    public AjaxResult delete(Long[] ids) {
        return AjaxResult.success(pStudentService.deleteStudentByIds(ids));
    }

}
